fn main() {
    println!("main");

    let mut count = 1;
    // 无限循环，使用break跳出
    loop {
        println!("{}. loop", count);
        // std::thread::sleep(std::time::Duration::from_secs(1));
        count += 1;
        if count == 10 {
            break;
        };
    }

    // break 通过标签跳出外层循环
    'outer: loop {
        println!("outer");
        loop {
            println!("mid");
            loop {
                println!("inner");
                break 'outer;
            }
        }
    }

    while count < 20 {
        println!("{}.while", count);
        count += 1;
    }

    let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
    for element in arr {
        if element == 5 {
            println!("{}.continue", element);
            continue;
        }
        println!("arr:{}", element);
    }

    for element in 0..10 {
        println!("ele1:{}", element);
    }

    for element in 0..=10 {
        println!("ele2:{}", element);
    }

    // 数组平方
    // 循环写法
    let numbers = [1, 2, 3, 4, 5];
    let mut for_numbers = Vec::new();
    for &number in numbers.iter() {
        let item = number * number;
        for_numbers.push(item);
    }
    println!("for : {:?}", for_numbers);
    // 迭代写法
    let numbers = [1, 2, 3, 4, 5].to_vec();
    let iter_number: Vec<_> = numbers.iter().map(|&x| x * x).collect();
    println!("iter:{:?}", iter_number);
    
}
